from components.VolumeInfo import VolumeInfo

cross_ball_radius = 10
# rgb
r_color = "rgb(255, 0, 0)"
g_color = "rgb(0, 255, 0)"
b_color = "rgb(0, 0, 255)"

default_mip = {
    "delta_x": 0,
    "delta_y": 0,
}


class CrossLayer:
    def __init__(self, view_type, volume_info):
        self.overlay = None
        self.view_type = view_type
        self.draw_image = None
        self.drawer = None
        self.volume_info: VolumeInfo = volume_info

    def get_layer(self):
        if self.view_type == 'stack':
            return None, None, None, default_mip
        return self.get_cross_position()

    def get_mip(self):
        mip = self.volume_info.get_mip_info(self.view_type)
        if mip is None:
            return default_mip
        return mip

    def get_cross_position(self):
        center = self.volume_info.get_cross_center(self.view_type)
        h_color, v_color = self.get_color()
        return center, h_color, v_color, self.get_mip()

    def get_color(self):
        if self.view_type == 'ax':
            h_color = g_color
            v_color = b_color
        elif self.view_type == 'sag':
            h_color = r_color
            v_color = g_color
        else:
            h_color = r_color
            v_color = b_color
        return h_color, v_color

    def draw_cross_line(self, center, w, h):
        center_x, center_y = center
        h_color, v_color = self.get_color()
        self.drawer.line([(0, center_y), (center_x - cross_ball_radius, center_y)], h_color, width=2)
        self.drawer.line([(center_x + cross_ball_radius, center_y), (w, center_y)], h_color, width=2)
        self.drawer.line([(center_x, 0), (center_x, center_y - cross_ball_radius)], v_color, width=2)
        self.drawer.line([(center_x, center_y + cross_ball_radius), (center_x, h)], v_color, width=2)
